<?php
require_once("../../../util/configuration/configuration_parametters.php");
require_once("../../../util/" . MESSAGES_PROPERTIES . "messages_model.php");
require_once("../../../util/exception/exception_handler.php");

require_once("../../article_article_category/to/article_article_category_to.php");
require_once("../../article_article_category/dao/article_article_category_dao_factory.php");

require_once("../../article/to/article_to.php");
require_once("../../article/dao/article_dao_factory.php");

require_once("../../article_category/to/article_category_to.php");
require_once("../../article_category/dao/article_category_dao_factory.php");

require_once("../../autor/to/autor_to.php");
require_once("../../autor/dao/autor_dao_factory.php");

class Article_article_category_dao_test {

	private $dao;
		
	private $autor;
	private $article;
	private $article_category;
		
	public function __construct() {		
	}
	
	public function before_test() {
	echo 'llego';
		$this->autor = (object) Autor_dao_factory::singleton()->get_dao()->create(new Autor_to('xxxxxxxxxxxx','password','email'));
		$date = date("Y-m-d H:i:s");
		$this->article = (object) Article_dao_factory::singleton()->get_dao()->create(new Article_to(0, 'title', $this->autor->get_login(), $date, 'open', 0));
		$this->article_category = (object) Article_category_dao_factory::singleton()->get_dao()->create(new Article_category_to(0,'title', 'description', 'xxxxxxxxxxxx', 0));

		$this->dao = Article_article_category_dao_factory::singleton()->get_dao();
	}
	
	public function run_test() {
		try {
			$article_article_category = new Article_article_category_to($this->article->get_number(), $this->article_category->get_number());
					
			$article_article_category = (object) $this->dao->create($article_article_category);		
			echo 'create<br/>';			

			echo 'article: '; 
			echo $article_article_category->to_string();
			echo '<br/>';
			
			if ($this->dao->exist($article_article_category->get_article_number(), 
									$article_article_category->get_article_category_number())) {

				$result = $this->dao->find_by_number_and_category_article($article_article_category->get_article_number(), 
																			$article_article_category->get_article_category_number());
				echo 'find<br/>';
				
				$aux_article_article_category = new Article_article_category_to($result['article_number'], $result['article_category_number']);
				if ($article_article_category->equals($aux_article_article_category)) 
					echo 'No hay update<br/>';
				
				
				$this->dao->remove($article_article_category->get_article_number(), 
									$article_article_category->get_article_category_number());
				echo 'remove<br/>';
				
			}
		}
		catch (Exception $e) {
			Exception_handler::singleton()->handler($e);
		}
	}
	
	public function after_test() {
		Article_category_dao_factory::singleton()->get_dao()->remove($this->article_category->get_number());
		Article_dao_factory::singleton()->get_dao()->remove($this->article->get_number());
		Autor_dao_factory::singleton()->get_dao()->remove($this->autor->get_login());
		
	}
}

//test
$test = new Article_article_category_dao_test();

$test->before_test();
$test->run_test();
$test->after_test();

?>